package com.gitee.wsl.mathematics.matrix.mat4.ext

import com.gitee.wsl.mathematics.matrix.mat4.Matrix4
import com.gitee.wsl.mathematics.matrix.mat4.MutableMatrix4

val <T:Number> Matrix4<T, *, *>.transpose get() = copy(
    m01 = this.m10,
    m10 = this.m01,
    m02 = this.m20,
    m20 = this.m02,
    m12 = this.m21,
    m21 = this.m12,
    m30 = this.m03,
    m13 = this.m31,
    m23 = this.m32
)

/**
 * Inplace operation: Transposes this matrix.
 */
fun<T:Number> MutableMatrix4<T, *, *>.transpose() {
    var t = m01; m01 = m10; m10 = t
    t = m02; m02 = m20; m20 = t
    t = m03; m03 = m30; m30 = t
    t = m12; m12 = m21; m21 = t
    t = m13; m13 = m31; m31 = t
    t = m23; m23 = m32; m32 = t
}